package com.landmesure.settings.fragment.tree;

import com.landmesure.settings.fragment.argsinfo.ArgumentsInfo;

import java.util.ArrayList;

public class TypeTreeNote implements Cloneable {
    private int id;    //节点ID(自身指定id)
    private int pid;    //父节点ID(子节点应具有的id标识）
    private int level;    //层级数
    private String name;    //节点名称
    private ArrayList<ArgumentsInfo> argumentsInfos;//节点信息集合

    private TypeTreeNote parentNote;    //父节点
    private ArrayList<TypeTreeNote> childNotes;   //子节点集合

    /**
     * 构造方法
     *
     * @param name 节点名称
     * @param id   节点id
     */
    TypeTreeNote(String name, int id, int pid, int level,
                 ArrayList<ArgumentsInfo> argumentsInfos) {
        this.name = name;
        this.id = id;
        this.pid = pid;
        this.level = level;
        this.argumentsInfos = argumentsInfos;
    }

    /**
     * 设置父节点指向
     *
     * @param parentNote 父节点
     * @return 自身实体实例
     */
    TypeTreeNote setParentNote(TypeTreeNote parentNote) {
        if (null == parentNote) {
            return this;
        }
        this.parentNote = parentNote;
        return this;
    }

    /**
     * 设置子节点指向
     *
     * @param childNotes 子节点实例集合
     */
    TypeTreeNote setChildNote(ArrayList<TypeTreeNote> childNotes) {
        if (null == childNotes || childNotes.isEmpty()) {
            return this;
        }
        this.childNotes = childNotes;
        return this;
    }

    public int getId() {
        return id;
    }

    public int getPid() {
        return pid;
    }

    public int getLevel() {
        return level;
    }

    public String getName() {
        return name;
    }

    public TypeTreeNote getParentNote() {
        return parentNote;
    }

    public ArrayList<TypeTreeNote> getChildNotes() {
        if (null == childNotes || childNotes.isEmpty()) {
            return null;
        }
        return childNotes;
    }

    public ArrayList<ArgumentsInfo> getArgumentsInfos() {
        if (null == argumentsInfos || argumentsInfos.isEmpty()) {
            return null;
        }
        return argumentsInfos;
    }

    @Override
    public Object clone() {
        TypeTreeNote noteClone = null;
        try {
            noteClone = (TypeTreeNote) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return noteClone;
    }
}
